require("../util.js");
require("../component/components.js");
require("../component/basicSlide.js");
require("../component/footer.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#happyiIndex",
    data:{
        userInfo:userInfo,
        loginUid:userInfo.id,
        // loginUid:1,
        recruit:{},
        happyiData:{},
        results:""
    },
    mounted:function(){
        this.myData();
        this.choiceRecruit()
    },
    methods:{
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //选择发布招聘
        choiceRecruit:function(){
            var that=this;
            var data={
                loginUid:that.loginUid
                // loginUid:1
            };
            this.ajax({url:"/happyi/choiceRecruit",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.recruit=b.json.data;
                    // that.list.title=that.applyInfo.functionsName;
                    // that.getEnterpriseRecruitList();
                }else{
                    location.href="/loginIndex";
                    vm.$refs.prompt.toast("获取信息失败！");
                }
            });
        },
        //选择发布招聘
        myData:function(){
            var that=this;
            var data={
                loginUid:that.loginUid
            };
            this.ajax({url:"/happyi/myData",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.happyiData=b.json.data;
                }else{
                    vm.$refs.prompt.toast("获取信息失败！");
                }
            });

        },
        //跳转
        getNext:function(type){
            if(type==0){  //编辑个人资料
                location.href="/happyi/userEdit"
            }else if(type==1||type==2||type==3||type==4){  // 1 视频  2 游记 3 收藏 4 点赞
                location.href="/happyi/myVideo?type="+type
            }else if(type==5||type==6){
                location.href="/happyi/myFans?type="+type
            }else if(type==7){
                location.href="/happyi/myWallet";
            }else if(type==8){
                location.href="/happyi/myCoupon";
            }else if(type==9){
                location.href="/happyi/todayMoney";
            }else if(type==10){
                location.href="/purchase/shoppingCart";
            }
        },
        myApply:function(type){
            var that=this;
            if(that.recruit.isEnterpriserecRuited==1){  //个人
                if(that.recruit.isUserResume==1){  //是否有简历
                    location.href="/happyi/myApply"
                }else{
                    vm.$refs.prompt.toast("请前往app编辑个人简历！");
                }
            }else if(that.recruit.isEnterpriserecRuited==2){
                if(that.recruit.isAuth==1){  //企业是否认证
                    if(that.recruit.idisEnterprise==1){
                        location.href="/happyi/companyRecruit?userEnterpriseId="+that.recruit.userEnterpriseId;
                    }else{
                        location.href="/happyi/editJob?type=1";
                    }

                }else{
                    vm.$refs.prompt.toast("请前往app认证企业！");
                }
            }else{
                vm.$refs.prompt.toast("请前往app认证！");
                // if(type==1){
                //     location.href="/happyi/myApply"
                // }else{
                //     location.href="/happyi/companyRecruit?userEnterpriseId="+that.recruit.userEnterpriseId;
                // }
            }
        },
        //设置-是否实名认证
        isRealName:function(){
            var that=this;
            var data={
                loginUid:that.loginUid
                // loginUid:1
            };
            this.ajax({url:"/happyi/isRealName",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    location.href="/happyi/authentication?state="+b.json.data.state;
                }else{
                    vm.$refs.prompt.toast("获取信息失败！");
                }
            });
        },
        getChange:function(){
            var that=this;
            that.headImg=$("#fileinput").get(0).files[0];
            //创建新文件对象
            that.headImg = new File([that.headImg], new Date().getTime()+".png",{type:"image/jpeg"});
            lrz(that.headImg, function (results) {
                // 你需要的数据都在这里，可以以字符串的形式传送base64给服务端转存为图片。
                console.log(results);
                that.results=results;
                that.setSecondInfo();
            });

        },
        //完善信息
        setSecondInfo:function(){
            var that=this;
            if(!that.headImg){
                vm.$refs.prompt.toast("请选择头像！");
                return false;
            }
            var formData = new FormData();
            formData.append("loginUid", that.loginUid);
            formData.append("headImg",that.headImg);
            // formData.append("name", userInfo.name);
            $.ajax({
                url:host+'/v1/user/updateUserHeadImg',
                type:'POST',
                data:formData,
                dataType:'json',
                async: false,
                cache: false,
                contentType: false, //不设置内容类型
                processData: false, //不处理数据
                success:function(data){
                    console.log(data);
                    // alert(data.msg);
                    if(data.code==0){
                        userInfo.headImg=data.data.headImg;
                        sessionStorage.setItem("userInfo",JSON.stringify(userInfo));
                    }
                },
                error:function(){
                    vm.$refs.prompt.toast("操作失败！")
                }
            });
        }
    }
});